﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace destructor_demo
{
    public class SampleClass
    {
        private static int objectCount = 0;
        public static event Action<int> OnCountChanged;

        private static int ObjectCount
        {
            get
            {
                return objectCount;
            }
            set
            {
                if (objectCount != value)
                {
                    objectCount = value;
                    if (OnCountChanged != null)
                        OnCountChanged(objectCount);
                }
            }
        }

        public SampleClass()
        {
            ObjectCount++;
        }

        ~SampleClass()
        {
            ObjectCount--;
        }
    }
}
